import URI from '@/services/uri';
import Request from '@/utils/request';

/*
{
      id,
      type: 'contractor',
      base64: dataUrl,
    }
    `${contractorInfo.cardNo}_${contractorInfo.surname}.zip`;
 */

export function downloadZip(data, filename) {
  return Request(URI.application.attachment.url, {
    method: 'POST',
    data,
    responseType: 'blob',
    requestType: 'form',
    timeout: 1000000,
  }).then(blob => {
    const a = document.createElement('a');
    const url = window.URL.createObjectURL(blob);
    a.href = url;
    a.download = filename;
    a.click();
    window.URL.revokeObjectURL(url);
  }).catch(e => {
    console.log('下載失敗了', e)
  });
}

export default {
  downloadZip,
};
